import _this from '@/main.js'

/**
 * 关闭当前页面
 */
export function closeCurrentTag() {
  const visitedViews = _this.$store.state.tagsView.visitedViews
  for (const view of visitedViews) {
    if (view.path === _this.$route.path) {
      _this.$store.dispatch('tagsView/delView', view).then(({ visitedViews }) => {
        const latestView = visitedViews.slice(-1)[0]
        if (latestView) {
          _this.$router.push(latestView)
        } else {
          if (view.name === 'Dashboard') {
            _this.$router.replace({ path: '/redirect' + view.fullPath })
          } else {
            _this.$router.push('/')
          }
        }
      })
    }
  }
}
